/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flarebit.flarebar;

import com.flarebit.flarebarlib.FlareUtils;
import com.flarebit.flarebarlib.Flaretab;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.agp.components.element.PixelMapElement;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.render.BlendMode;
import ohos.agp.utils.Color;
import ohos.app.Context;
import ohos.media.image.PixelMap;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * 单元测试
 *
 * @since 2021-06-23
 */
public class ExampleOhosTest {
    private Context mContext = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility().getContext();

    /**
     * 包名测试
     */
    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("com.flarebit.flarebar", actualBundleName);
    }

    /**
     * 获取PixelMap测试
     */
    @Test
    public void testPixelMapFromResource() {
        PixelMap pixelMap = FlareUtils.getPixelMapFromResource(mContext, ResourceTable.Media_inboxb);
        assertNotNull(pixelMap);
    }

    /**
     * 颜色过滤器测试
     */
    @Test
    public void testTintElement() {
        ShapeElement element = new ShapeElement(mContext, ResourceTable.Graphic_background_ability_main);
        ShapeElement tintElement = FlareUtils.getTintElement(element,
                Color.getIntColor("#FFFFECB3"), BlendMode.SRC_ATOP);
        assertNotNull(tintElement);
    }

    /**
     * Flare tab测试
     */
    @Test
    public void testFlareTab() {
        PixelMap pixelMap = FlareUtils.getPixelMapFromResource(mContext, ResourceTable.Media_inboxb);
        Flaretab flaretab = new Flaretab(new PixelMapElement(pixelMap), "Inbox", "#FFFFECB3");
        assertNotNull(flaretab);
    }

    /**
     * Badge and flare tab测试
     */
    @Test
    public void testBadgeFlareTab() {
        PixelMap pixelMap = FlareUtils.getPixelMapFromResource(mContext, ResourceTable.Media_avatarb);
        Flaretab flaretab = new Flaretab(new PixelMapElement(pixelMap), "Profile", "#FFEF9A9A", "4");
        assertNotNull(flaretab);
    }
}